<?php
class ControllerAccountRechargeHistory extends Controller {
	public function index() {
		if (!$this->customer->isLogged()) {
			$this->session->data['redirect'] = $this->url->link('account/recharge_history', '', 'SSL');

			$this->redirect($this->url->link('account/login', '', 'SSL'));
		}

		$this->language->load('account/recharge_history');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),        	
			'separator' => false
		);

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_account'),
			'href'      => $this->url->link('account/account', '', 'SSL'),       	
			'separator' => $this->language->get('text_separator')
		);

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_recharge_historys'),
			'href'      => $this->url->link('account/recharge_history', '', 'SSL'),       	
			'separator' => $this->language->get('text_separator')
		);

		$this->load->model('account/recharge');

		$recharge_history_total = $this->model_account_recharge->getTotalRechargeHistorys();

        $this->data['heading_title'] = $this->language->get('heading_title');

        $this->data['button_continue'] = $this->language->get('button_continue');

		if ($recharge_history_total) {
			if (isset($this->request->get['page'])) {
				$page = $this->request->get['page'];
			} else {
				$page = 1;
			}
            $data = array(
                'start'                  => ($page - 1) * $this->config->get('config_catalog_limit'),
                'limit'                  => $this->config->get('config_catalog_limit')
            );
			$this->data['recharge_historys'] = array();

			$results = $this->model_account_recharge->getRechargeHistorys($data);

			foreach ($results as $result) {
                if($result['type']=='present'){
                       $type='系统赠送';
                }else{
                       $type='充值';
                }
                $this->data['recharge_historys'][] = array(
                    'recharge_order_id'   => $result['recharge_order_id'],
                    'price'   => $result['price'],
                    'type'   => $type,
                    'date'   => $result['date'],
                );
			}

			$pagination = new Pagination();
			$pagination->total = $recharge_history_total;
			$pagination->page = $page;
			$pagination->limit = $this->config->get('config_catalog_limit');
			$pagination->text = $this->language->get('text_pagination');
			$pagination->url = $this->url->link('account/recharge_history', 'page={page}', 'SSL');

			$this->data['pagination'] = $pagination->render();
		}else{

        }

        $this->data['continue'] = $this->url->link('account/account', '', 'SSL');

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/recharge_history.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/account/recharge_history.tpl';
        } else {
            $this->template = 'default/template/account/recharge_history.tpl';
        }

        $this->children = array(
            'common/column_left',
            'common/column_right',
            'common/content_top',
            'common/content_bottom',
            'common/footer',
            'common/header'
        );

        $this->response->setOutput($this->render());

    }

}
?>